<div class="widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 新增雇员 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-users"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- TODO 门店信息 -->
		<div class="widget radius-bordered" id="editor-panel-users">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i>
				<span class="widget-caption"> <a href="" data-toggle="collapse"> 选择门店 </a> </span>
			</div>
			<div class="widget-body editor-body-sm">
				<table data-ajax="handlerSearch" 
							 data-method="post"
							 data-id-field="id" 
							 data-unique-id="id" 
							 data-pagination="false"  
							 data-check-on-init="true" 
							 data-click-to-select="true" 
							 data-side-pagination="server" 
							 data-mobile-responsive="true" 
							 data-form-search="#search-form-shops" id="table-shops">
					<thead>
						<tr>
							<th data-radio="true"></th>
							<th data-field="id" 			data-visible="false" data-switchable="false">ID</th>
							<th data-field="name" 		data-align="center" >店名</th>
							<th data-field="address" 	data-align="center" >地址</th>
						</tr>
					</thead>
				</table>
			</div>			
		</div>
		
		<!-- TODO 基本信息 -->
		<div class="widget radius-bordered">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 基本信息 </span>
			</div>
			<div class="widget-body editor-body-sm">
				<form class="form-horizontal form-editor form-editor-users">
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="deptsid">部门</label>
								<div class="col-sm-8">
									<select name="depts.id" id="deptsid" class="chosen-select" data-entity="com.app.miwawa.api.system.entity.center.Depts">
									</select>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="duty">职务</label>
								<div class="col-sm-8">
									<input name="users.duty" id="duty" type="text" class="form-control"> 
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="createDate">入职时间</label>
								<div class="col-sm-8">
									<div class="input-group date date-selector">
										<input name="users.createDate" id="createDate" type="text" class="form-control"> 
										<span class="input-group-addon">
											<span class="fa fa-calendar"></span>
										</span>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label required" for="name">姓名</label>
								<div class="col-sm-8">
									<input name="users.name" id="name" type="text" class="form-control" required="required">
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="sex">性别</label>
								<div class="col-sm-8">
									<div class="input-group">
										<label class="radio-inline c-radio"> 
											<input type="radio" name="users.sex" value="男"/> 
											<span class="fa fa-check"></span> 男
										</label> 
										<label class="radio-inline c-radio"> 
											<input type="radio" name="users.sex" value="女" checked="checked"/> 
											<span class="fa fa-check"></span> 女
										</label>
									</div>
								</div>
							</div>
						</div>
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label" for="type">是否兼职</label>
								<div class="col-sm-8">
									<div class="input-group">
										<label class="radio-inline c-radio"> 
											<input type="radio" name="users.type" value="兼职"/> 
											<span class="fa fa-check"></span> 是
										</label> 
										<label class="radio-inline c-radio"> 
											<input type="radio" name="users.type" value="全职" checked="checked"/> 
											<span class="fa fa-check"></span> 否
										</label>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-4">
							<div class="form-group">
								<label class="col-sm-4 control-label required" for="mobile">手机</label>
								<div class="col-sm-8">
									<input type="text" name="users.mobile" id="mobile" class="form-control" required="required"/>
								</div>
							</div>
						</div>
						<div class="col-sm-8">
							<div class="form-group">
								<label class="col-sm-2 control-label" for="email">邮箱</label>
								<div class="col-sm-10">
									<input type="text" name="users.email" id="email" class="form-control" />
								</div>
							</div>
						</div>
					</div>
					
					<div class="widget-footer editor-footer-sm">
						<button type="button" class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="取消" onclick="handlerCancel(this);" data-refresh-table="#table-users">
							<i class="glyphicon glyphicon-remove"></i>
						</button>
						<button type="button" class="btn btn-primary btn-sm" data-toggle="tooltip" data-placement="top" title="保存" onclick="handlerSubmit(this, '#editor-form-users', '.form-editor-users');" data-submit-callback="loadGroups">
							<i class="glyphicon glyphicon-ok"></i>
						</button>
					</div>
				</form>
			</div>
		</div>
		
				<!-- TODO 角色配置 -->
		<div class="widget radius-bordered hidden" id="editor-panel-groups">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 角色配置 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-groups">
				<div id="tree" data-entity="com.app.miwawa.api.system.entity.Groups"></div>
				
				<div class="widget-footer editor-footer-sm">
					<button type="button" class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="取消" onclick="handlerCancel(this);" data-refresh-table="#table-groups">
						<i class="glyphicon glyphicon-remove"></i>
					</button>
					<button type="button" class="btn btn-primary btn-sm" data-toggle="tooltip" data-placement="top" title="保存" onclick="handlerTree(this);">
						<i class="glyphicon glyphicon-ok"></i>
					</button>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- 提交表单 ========================================================= -->
<form id="editor-form-users" action="/miwawa/default/users/save" method="post" 
			name="com.app.miwawa.api.system.entity.center.Users"
			data-show-target="#editor-panel-groups" 
			data-custom-action="true">
			<input type="hidden" name="users.status" value="0">
			<input type="hidden" name="users.invalid" value="F">
</form>
<!-- 查询表单 ========================================================= -->
<form id="search-form-shops" action="/miwawa/default/common/search.json" method="post" 
			name="com.app.miwawa.api.system.entity.center.Shops">
			<input type="hidden" name="status" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="centerid" value="0" data-search-group="and" data-search-operation="EQ">
			<input type="hidden" data-search-sort="createDate" data-search-order="desc">
</form>
    
<script type="text/javascript">
<!--
	jQuery(function() {
		
		require(['jquery.plugin.form'],function(form){
			form.tooltip("[data-toggle='tooltip']");
			form.datepicker('.date-selector');
			
			form.chosen("#deptsid");
			
			jQuery(":hidden[name='centerid']",'#search-form-shops').val(centerid);
			jQuery("#table-shops").bootstrapTable({
				onClickRow:function(row, $element){
					loadDepts(form, row.id);
				},
				onLoadSuccess:function(data){
					jQuery("#table-shops").bootstrapTable("check",0);
					loadDepts(form, data.rows[0].id);
				}
			});
		});
	});
	
	function loadDepts(form, shopsid){
		jQuery("#deptsid").empty();
		form.select("#deptsid",{ 
			url:"/miwawa/default/common/select.json",
			querys:{"shopsid_EQ":shopsid} 
		});
	}
	
	function loadGroups() {
		require(['jquery.bootstrap.tree'],function(tree){
			tree.init("#tree", {
				url: "/miwawa/system/groups/"+jQuery("#editor-form-users").data("com.app.miwawa.api.system.entity.center.Users")+"/tree.json",
				querys: {
					"and": [{"operator":"EQ", "fieldName":"systemid", "fieldValue":"297ebe0e53d648370153d64dbefc0002"}],
					"order": [{"sort":"sort", "order":"asc"}]
				}
			});
		});
	}
	
	function handlerTree(trigger){
		var params = [], nodes = jQuery('#tree').treeview('getChecked');
		
		if(nodes == null || nodes.length <= 0){
			jQuery.message.warning("请选择要配置的角色！");
			return;
		}
		
		if(nodes.length > 1){ 
			jQuery.message.warning("每个人只能配置一个角色！");
			return;
		}
		
	 	for(var i in nodes){
			var node = nodes[i];
			params.push({
				"source": "Users",
				"sourceid": jQuery("#editor-form-users").data("com.app.miwawa.api.system.entity.center.Users"),
				"target": "Groups",
				"targetid": node.id,
				"status": "0",
				"invalid": "F"
			});
		}
		
		jQuery.ajaxsend({
			url: "/miwawa/system/groups/"+jQuery("#editor-form-users").data("com.app.miwawa.api.system.entity.center.Users")+"/update",
			data: {
				"entityClass": "com.app.miwawa.api.system.entity.center.Relation",
				"beans": params
			},
			success: function(data){
				if(data){
					jQuery(trigger).parent().hide();
				}
			}
		});
	}
//-->
</script>